package com.xja.main;

import com.xja.controller.LwdController;
import com.xja.controller.LwlController;
import com.xja.controller.ZcyController;
import com.xja.entity.*;
import com.xja.entity.pojo.UrByIndent;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
/**
 * @author 翻斗乐园
 * @create 2022-05-05 12:19
 */
public class MainText {
    public static void main(String[] args) {
        LwdController lwdController=new LwdController();
        ZcyController controller = new ZcyController();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Scanner input = new Scanner(System.in);
        while (true){
            System.out.println("1.用户管理");
            System.out.println("2.入住登记");
            System.out.println("3.管理员管理");
            System.out.println("4.房情管理");
            System.out.println("5.订单管理");
            System.out.println("6.账单统计");
            System.out.println("7.退出");
            System.out.println("请输入你的选择:");
            int key = input.nextInt();
            switch (key){
                case 1:

                    while (true){
                        System.out.println("用户信息管理");
                        System.out.println("1.用户信息查询");
                        System.out.println("2.用户信息修改");
                        System.out.println("3.删除用户信息");
                        int i=input.nextInt();
                        switch (i){
                            case 1:
                                List<User> userlist=lwdController.findAllUser();
                                for (User user : userlist) {
                                    System.out.println(user);
                                }
                                break;
                            case 2:
                                System.out.println("输入用户的id");
                                Integer userId=input.nextInt();
                                User user=lwdController.findUserById(userId);
                                if (user!=null){
                                    System.out.println("用户的名字为：");
                                    System.out.println(user.getUserName());
                                    System.out.println("请输入你的修改：");
                                    String userName=input.next();

                                    System.out.println("用户的电话为：");
                                    System.out.println(user.getUserPhone());
                                    System.out.println("请输入你的修改：");
                                    String userPhone=input.next();

                                    System.out.println("用户的性别为：");
                                    System.out.println(user.getUserGender());
                                    System.out.println("请输入你的修改：");
                                    String userGender=input.next();

                                    System.out.println("用户的身份证号为：");
                                    System.out.println(user.getUserCard());
                                    System.out.println("请输入你的修改：");
                                    String userCard=input.next();

                                    System.out.println("用户的等级为：");
                                    System.out.println(user.getUserLevel());
                                    System.out.println("请输入你的修改：");
                                    Integer userlev=input.nextInt();

                                    System.out.println("用户的密码为：");
                                    System.out.println(user.getUserPassWord());
                                    System.out.println("请输入你的修改：");
                                    String userPassword=input.next();

                                    User user1=new User(userId,userName,userPhone,userGender,userCard,userlev,userPassword);
                                    if (lwdController.updateUser(user1)){
                                        System.out.println("修改成功");
                                    }else {
                                        System.out.println("修改失败");
                                    }
                                }else System.out.println("用户不存在");
                                break;
                            case 3:
                                System.out.println("输入用户的id");
                                Integer userId1=input.nextInt();
                                User user2=lwdController.findUserById(userId1);
                                if (user2!=null){
                                    if (lwdController.deleUser(userId1)){
                                        System.out.println("删除成功");
                                    }else System.out.println("删除失败");
                                }else System.out.println("用户不存在");
                                break;
                            default:
                                System.out.println("输入字符违法");
                                break;
                        }
                        System.out.println("是否继续用户管理功能Y/N");
                        String next = input.next();
                        if ("N".equalsIgnoreCase(next)){
                            break;
                        }
                    }
                    break;
                case 2:
                    System.out.println("输入你的id");
                    Integer userId=input.nextInt();
                    User user= lwdController.findUserById(userId);
                    Indent indent=lwdController.findIndentById(userId);
                    if (user!=null){
                        if (indent!=null){
                            Register register=lwdController.createRegisterByUserId(userId);
                            System.out.println(register);
                            //事务处理：等级表添加、预定表删除
                            if (lwdController.updateRegisterAndIndent(register)){
                                System.out.println("登记添加成功");
                            }else System.out.println("登记失败");
                        }else {
                            System.out.println("您还没有预定");
                        }

                        //
                    }else System.out.println("用户不存在，请先注册");
                    break;
                case 3:
                    while (true){
                        System.out.println("---员工管理---");
                        System.out.println("1.查询所有员工");
                        System.out.println("2.员工信息查询");
                        System.out.println("3.员工信息修改");
                        System.out.println("4.添加新的员工");
                        System.out.println("5.删除用户信息");
                        int i=input.nextInt();
                        switch (i){
                            case 1:
                                List<WorkPeople> list= lwdController.findAllWork();
                                for (WorkPeople workPeople : list) {
                                    System.out.println(workPeople);
                                }
                                break;
                            case 2:
                                System.out.println("输入你的员工编号");
                                Integer i3=input.nextInt();
                                WorkPeople workPeople= lwdController.findWorkById(i3);
                                if (workPeople!=null){
                                    System.out.println(workPeople);
                                }else System.out.println("未查到员工信息");
                                break;
                            case 3:
                                System.out.println("输入你的员工编号");
                                Integer i4=input.nextInt();
                                WorkPeople workPeople1= lwdController.findWorkById(i4);
                                if (workPeople1!=null){
                                    System.out.println("员工的名字为：");
                                    System.out.println(workPeople1.getWorkPeopleName());
                                    System.out.println("请输入你的修改：");
                                    String workName=input.next();

                                    System.out.println("员工的电话为：");
                                    System.out.println(workPeople1.getWorkPeoplePhone());
                                    System.out.println("请输入你的修改：");
                                    String workPhone=input.next();

                                    System.out.println("员工的性别为：");
                                    System.out.println(workPeople1.getWorkPeopleGender());
                                    System.out.println("请输入你的修改：");
                                    String workGender=input.next();

                                    System.out.println("员工的身份证号为：");
                                    System.out.println(workPeople1.getWorkPeopleCard());
                                    System.out.println("请输入你的修改：");
                                    String workCard=input.next();

                                    System.out.println("员工的工作为：");
                                    System.out.println(workPeople1.getWorkPeopleType());
                                    System.out.println("请输入你的修改：");
                                    String workType=input.next();

                                    System.out.println("员工的月薪为：");
                                    System.out.println(workPeople1.getWorkPeopleMonthSalary());
                                    System.out.println("请输入你的修改：");
                                    Integer workSala =input.nextInt();

                                    System.out.println("员工的级别为：");
                                    System.out.println(workPeople1.getWorkPeopleLevel());
                                    System.out.println("请输入你的修改：");
                                    Integer workLeve=input.nextInt();

                                    WorkPeople workPeople2 = new WorkPeople(i4,workName,workPhone,workGender,workCard,workType,workSala,workLeve);
                                    if (lwdController.updateWork(workPeople2)){
                                        System.out.println("修改成功");
                                    }else System.out.println("修改失败");
                                }else System.out.println("未查到员工信息");
                                break;
                            case 4:
                                System.out.println("员工的名字为：");
                                String name= input.next();
                                System.out.println("员工的电话为：");
                                String tel= input.next();
                                System.out.println("员工的性别为：");
                                String sex= input.next();
                                System.out.println("员工的身份证号为：");
                                String card= input.next();
                                System.out.println("员工的工作为：");
                                String work=input.next();
                                System.out.println("员工的月薪为：");
                                Integer sala=input.nextInt();
                                System.out.println("员工的级别为：");
                                Integer leve= input.nextInt();
                                WorkPeople workPeople2 = new WorkPeople(name,tel,sex,card,work,sala,leve);
                                if (lwdController.addWork(workPeople2))
                                    System.out.println("添加成功");
                                else System.out.println("添加失败");
                                break;
                            case 5:
                                System.out.println("输入你的员工编号");
                                Integer is=input.nextInt();
                                WorkPeople workPeople3= lwdController.findWorkById(is);
                                if (workPeople3!=null){
                                    if (lwdController.deleWork(is)){
                                        System.out.println("删除成功");
                                    }else System.out.println("删除失败");
                                }else System.out.println("未查到员工信息，删除失败");
                                break;
                            default:
                                System.out.println("输入字符违法");
                                break;
                        }
                        System.out.println("是否继续员工管理功能Y/N");
                        String next = input.next();
                        if ("N".equalsIgnoreCase(next)){
                            break;
                        }
                    }
                    break;
                case 4:
                    System.out.println("---房情管理页面---");
                    while (true) {
                        System.out.println("1.查看所有房情");
                        System.out.println("2.增加一个房情");
                        System.out.println("3.根据ID修改房情");
                        System.out.println("4.根据ID删除房情");
                        int k = input.nextInt();
                        switch (k) {
                            case 1:
                                List<Room> Roomlist = controller.findRoom();
                                for (Room room : Roomlist) {
                                    System.out.println(room);
                                }
                                break;
                            case 2:
                                Room room = new Room();
                                System.out.println("请输入增加的房间种类");
                                room.setRoomKind(input.next());
                                System.out.println("请输入增加的房间价格");
                                room.setRoomPrice(input.nextInt());
                                System.out.println("请输入增加的房间楼层");
                                room.setRoomFloor(input.nextInt());
                                System.out.println("请输入增加的房间状态(0是无房，1是有房)");
                                room.setRoomStatus(input.nextInt());
                                System.out.println("请输入增加的房间名字");
                                room.setRoomName(input.next());
                                boolean f = controller.addRoom(room);
                                if (f){
                                    System.out.println("添加成功");
                                }else {
                                    System.out.println("添加失败");
                                }
                                break;
                            case 3:
                                System.out.println("情输入你要修改的id");
                                int updateId = input.nextInt();
                                Room findRoom=controller.findRoomById(updateId);
                                Room updateroom = new Room();
                                System.out.println("原房间种类为"+findRoom.getRoomKind()+",请输入修改的房间种类");
                                updateroom.setRoomKind(input.next());
                                System.out.println("原房间价格为"+findRoom.getRoomPrice()+",请输入修改的房间价格");
                                updateroom.setRoomPrice(input.nextInt());
                                System.out.println("原房间楼层为"+findRoom.getRoomFloor()+",请输入修改的房间楼层");
                                updateroom.setRoomFloor(input.nextInt());
                                System.out.println("原房间状态为"+findRoom.getRoomStatus()+",请输入修改的房间状态(0表示已入住，1表示有房)");
                                updateroom.setRoomStatus(input.nextInt());
                                System.out.println("原房间名字为"+findRoom.getRoomName()+",请输入修改的房间名字");
                                updateroom.setRoomName(input.next());
                                updateroom.setRoomId(findRoom.getRoomId());
                                boolean f1 = controller.updateRoom(updateroom);
                                if (f1){
                                    System.out.println("添加成功");
                                }else {
                                    System.out.println("添加失败");
                                }
                                break;
                            case 4:
                                System.out.println("请输入你要删除的id");
                                int deleteId = input.nextInt();
                                boolean flag=controller.deleteRoomById(deleteId);
                                if (flag){
                                    System.out.println("success");
                                }else {
                                    System.out.println("defete");
                                }
                                break;
                            default:
                                System.out.println("输入有误再次输入");
                                break;
                        }
                        System.out.println("是否继续房情管理功能Y/N");
                        String next = input.next();
                        if ("N".equalsIgnoreCase(next)){
                            break;
                        }
                    }
                    break;
                case 5:
                    System.out.println("---订单管理页面---");
                    while (true) {
                        System.out.println("1.查看所有订单");
                        System.out.println("2.根据用户名更新订单");
                        System.out.println("3.根据ID删除订单");
                        int k = input.nextInt();
                        switch (k) {
                            case 1:
                                List<UrByIndent> indentList = controller.FindAllIndent();
                                for (UrByIndent urByIndent : indentList) {
                                    System.out.println(urByIndent);
                                }
                                break;
                            case 2:
                                System.out.println("请输入要更新的客户名:");
                                String name = input.next();
                                Indent updateIndent = new Indent();
                                List<UrByIndent> indentList1 = controller.FindAllIndent();
                                boolean flagIndent=false;
                                for (UrByIndent urByIndent : indentList1) {
                                    if (urByIndent.getUser().getUserName().equals(name)){
                                        System.out.println("原订单信息是"+urByIndent);
                                        updateIndent.setIndentId(urByIndent.getIndent().getIndentId());
                                        updateIndent.setUserId(urByIndent.getUser().getUserId());
                                        List<Room> roomList = controller.findRoom();
                                        System.out.println("空房间如下：");
                                        for (Room room : roomList) {
                                            if (room.getRoomStatus()==1){
                                                System.out.println(room);
                                            }
                                        }
                                        System.out.println("修改的房间编号是");
                                        updateIndent.setRoomId(input.nextInt());
                                        System.out.println("更新的入住的时间");
                                        String time = input.next();
                                        try {
                                            updateIndent.setCheckTime(sdf.parse(time));
                                        } catch (ParseException e) {
                                            e.printStackTrace();
                                        }
                                        System.out.println("要更新的入住时长");
                                        updateIndent.setDuratiom(input.nextInt());
                                        System.out.println("需要更新的备注是");
                                        updateIndent.setRemark(input.next());
                                        flagIndent=controller.updateIndent(updateIndent);
                                        controller.updateStatusById(urByIndent.getRoom().getRoomId(),1);
                                        break;
                                    }
                                }
                                if (flagIndent){
                                    System.out.println("更新成功");
                                    Integer updateStatus=0;
                                    boolean f=controller.updateStatusById(updateIndent.getRoomId(),updateStatus);
                                }else{
                                    System.out.println("更新失败");
                                }
                                break;
                            case 3:
                                System.out.println("请输入你要删除的id");
                                int deleteIndentById = input.nextInt();
                                boolean flag=controller.deleteIndentById(deleteIndentById);
                                if (flag){
                                    System.out.println("success");
                                }else {
                                    System.out.println("defete");
                                }
                                break;
                            default:
                                System.out.println("输入有误再次输入");
                                break;
                        }
                        System.out.println("是否继续订单管理功能Y/N");
                        String next = input.next();
                        if ("N".equalsIgnoreCase(next)){
                            break;
                        }
                    }
                    break;
                case 6:
                    HashMap<String, String> map = controller.findBroom();
                    for (String s : map.keySet()) {
                        System.out.println("房间种类为: "+s+" 该种类的总消费为:"+map.get(s));
                    }
                    break;
                case 7:
                    System.exit(0);
                    break;
                default:
                    System.out.println("输入有误");
                    break;
            }
        }
    }
}

